﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Dosimetria.Models;
using Dosimetria.Models.DataAnnotations_Classes.Authentication;
using Dosimetria.Authorization;
using System.Web.Security;
using Dosimetria.Models.DataAnnotations_Classes;

namespace Dosimetria.Controllers
{
    public class HomeController : Controller
    {
        public ActionResult Index()
        {
           
            return View();
        }

        [HttpPost] 
        public ActionResult Index(Login login)
        {
            if(Dosimetria.Authorization.Membership.ValidateUser(login))
            {
                FormsAuthentication.SetAuthCookie(login.UsernName, false);
                return RedirectToAction("Inicio", "Home");
            }
            else
            {
                return View();
            }
        }

        public ActionResult Inicio()
        {
            return View();
        }

        public ActionResult About()
        {
            
            return View();
        }

        public ActionResult CargarMenu()
        {
            List<Sistema> sistemas = Authorization.Membership.GetFuncionalidades(HttpContext.User.Identity.Name);
            return View(sistemas);
        }

        public ActionResult CerrarSesion()
        {
            FormsAuthentication.SignOut();
            
            return RedirectToAction("Index", "Home");
        }
    }
}
